﻿using System;
using Microsoft.Practices.ObjectBuilder;
using AP.LUNA.Commons;

namespace AP.LUNA.Shell.Views
{
    public partial class AdministrarDesempenosComprension : Microsoft.Practices.CompositeWeb.Web.UI.UserControl, IAdministrarDesempenosComprensionView
    {
        private AdministrarDesempenosComprensionPresenter _presenter;

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.IsPostBack)
            {
                this._presenter.OnViewInitialized();
            }
            this._presenter.OnViewLoaded();
        }

        [CreateNew]
        public AdministrarDesempenosComprensionPresenter Presenter
        {
            get
            {
                return this._presenter;
            }
            set
            {
                if (value == null)
                    throw new ArgumentNullException("value");

                this._presenter = value;
                this._presenter.View = this;
            }
        }

        // TODO: Forward events to the presenter and show state to the user.
        // For examples of this, see the View-Presenter (with Application Controller) QuickStart:
        //	

        public event EventHandler ClickGuardar;
        private void OnClickGuardar(object sender, EventArgs e)
        {
            if (this.ClickGuardar != null)
                ClickGuardar(sender, e);
        }

        public event EventHandler ClickVolver;
        private void OnClickVolver(object sender, EventArgs e)
        {
            if (this.ClickVolver != null)
                ClickVolver(sender, e);
        }

        public int IdAsignatura
        {
            get
            {
                return (int)ViewState["IdAsignatura"];
            }
            set
            {
                ViewState["IdAsignatura"] = value;
            }
        }

        public int IdEscala
        {
            get
            {
                return int.Parse(this.ddlEscala.SelectedValue);
            }
            set
            {
                this.ddlEscala.SelectedValue = value.ToString();
            }
        }

        public int IdPeriodo
        {
            get
            {
                return int.Parse(this.ddlPeriodo.SelectedValue);
            }
            set
            {
                this.ddlPeriodo.SelectedValue = value.ToString();
            }
        }

        public object ListDesempenos
        {
            set
            {
                this.gvDesempenos.DataSource = value;
                this.gvDesempenos.DataBind();
            }
        }

        public object ListPeriodos
        {
            set
            {
                this.ddlPeriodo.DataSource = value;
                this.ddlPeriodo.DataBind();
            }
        }

        public object ListEscalas
        {
            set
            {
                this.ddlEscala.DataSource = value;
                this.ddlEscala.DataBind();
            }
        }

        public string Msgresult
        {
            set { WebUtil.MostrarMensaje(Constanst.TITULO, value); }
        }

        public int IndexView
        {
            set { this.MultiView1.ActiveViewIndex = value; }

        }

        public void Limpiar()
        {
            WebUtil.CleanControl(this);
        }
        protected void lkbVolver_Click(object sender, EventArgs e)
        {
            OnClickVolver(sender, e);
        }


        public string Operacion
        {
            get
            {
                return (string)ViewState["Operacion"];
            }
            set
            {
                ViewState["Operacion"] = value;
            }
        }


        public void CargarDesempeños()
        {
            this.Presenter.CargarDesempenos();
        }

        protected void gvDesempenos_RowCommand(object sender, System.Web.UI.WebControls.GridViewCommandEventArgs e)
        {
            this.Operacion = e.CommandName;
            //int index = int.Parse(e.CommandArgument.ToString());
            switch (this.Operacion)
            {
                case "Nuevo":
                    this.IndexView = 1;
                    break;
                case "Editar":
                    break;
                case "Eliminar":
                    break;
            }
        }
        protected void lkbGuardar_Click(object sender, EventArgs e)
        {
            this.Presenter.Guardar();
            OnClickGuardar(sender, e);
        }
        protected void lkbCancelar_Click(object sender, EventArgs e)
        {
            this.IndexView = 0;
        }


        public string Descripcion
        {
            get
            {
                return this.txtTema.Text;
            }
            set
            {
                this.txtTema.Text = value;
            }
        }
    }
}